<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Widgets &mdash; Django 1.7.8.dev20150401230226 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '1.7.8.dev20150401230226',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="Django 1.7.8.dev20150401230226 documentation" href="../../index.html" />
    <link rel="up" title="Forms" href="index.html" />
    <link rel="next" title="Form and field validation" href="validation.html" />
    <link rel="prev" title="Formset Functions" href="formsets.html" />



 
<script type="text/javascript" src="../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 1.7.8.dev20150401230226 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../index.html">Home</a>  |
        <a title="Table of contents" href="../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../genindex.html">Index</a>  |
        <a title="Module index" href="../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="formsets.html" title="Formset Functions">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="validation.html" title="Form and field validation">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-forms-widgets">
            
  <div class="section" id="s-module-django.forms.widgets">
<span id="s-widgets"></span><span id="module-django.forms.widgets"></span><span id="widgets"></span><h1>Widgets<a class="headerlink" href="#module-django.forms.widgets" title="Permalink to this headline">¶</a></h1>
<p>A widget is Django&#8217;s representation of a HTML input element. The widget
handles the rendering of the HTML, and the extraction of data from a GET/POST
dictionary that corresponds to the widget.</p>
<div class="admonition tip">
<p class="first admonition-title">Tip</p>
<p class="last">Widgets should not be confused with the <a class="reference internal" href="fields.html"><em>form fields</em></a>.
Form fields deal with the logic of input validation and are used directly
in templates. Widgets deal with rendering of HTML form input elements on
the web page and extraction of raw submitted data. However, widgets do
need to be <a class="reference internal" href="#widget-to-field"><em>assigned</em></a> to form fields.</p>
</div>
<div class="section" id="s-specifying-widgets">
<span id="s-widget-to-field"></span><span id="specifying-widgets"></span><span id="widget-to-field"></span><h2>Specifying widgets<a class="headerlink" href="#specifying-widgets" title="Permalink to this headline">¶</a></h2>
<p>Whenever you specify a field on a form, Django will use a default widget
that is appropriate to the type of data that is to be displayed. To find
which widget is used on which field, see the documentation about
<a class="reference internal" href="fields.html#built-in-fields"><em>Built-in Field classes</em></a>.</p>
<p>However, if you want to use a different widget for a field, you can
just use the <a class="reference internal" href="fields.html#django.forms.Field.widget" title="django.forms.Field.widget"><tt class="xref py py-attr docutils literal"><span class="pre">widget</span></tt></a> argument on the field definition. For
example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>

<span class="k">class</span> <span class="nc">CommentForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">()</span>
    <span class="n">url</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">URLField</span><span class="p">()</span>
    <span class="n">comment</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">widget</span><span class="o">=</span><span class="n">forms</span><span class="o">.</span><span class="n">Textarea</span><span class="p">)</span>
</pre></div>
</div>
<p>This would specify a form with a comment that uses a larger <a class="reference internal" href="#django.forms.Textarea" title="django.forms.Textarea"><tt class="xref py py-class docutils literal"><span class="pre">Textarea</span></tt></a>
widget, rather than the default <a class="reference internal" href="#django.forms.TextInput" title="django.forms.TextInput"><tt class="xref py py-class docutils literal"><span class="pre">TextInput</span></tt></a> widget.</p>
</div>
<div class="section" id="s-setting-arguments-for-widgets">
<span id="setting-arguments-for-widgets"></span><h2>Setting arguments for widgets<a class="headerlink" href="#setting-arguments-for-widgets" title="Permalink to this headline">¶</a></h2>
<p>Many widgets have optional extra arguments; they can be set when defining the
widget on the field. In the following example, the
<a class="reference internal" href="#django.forms.extras.widgets.SelectDateWidget.years" title="django.forms.extras.widgets.SelectDateWidget.years"><tt class="xref py py-attr docutils literal"><span class="pre">years</span></tt></a> attribute is set
for a <a class="reference internal" href="#django.forms.extras.widgets.SelectDateWidget" title="django.forms.extras.widgets.SelectDateWidget"><tt class="xref py py-class docutils literal"><span class="pre">SelectDateWidget</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>
<span class="kn">from</span> <span class="nn">django.forms.extras.widgets</span> <span class="kn">import</span> <span class="n">SelectDateWidget</span>

<span class="n">BIRTH_YEAR_CHOICES</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;1980&#39;</span><span class="p">,</span> <span class="s">&#39;1981&#39;</span><span class="p">,</span> <span class="s">&#39;1982&#39;</span><span class="p">)</span>
<span class="n">FAVORITE_COLORS_CHOICES</span> <span class="o">=</span> <span class="p">((</span><span class="s">&#39;blue&#39;</span><span class="p">,</span> <span class="s">&#39;Blue&#39;</span><span class="p">),</span>
                            <span class="p">(</span><span class="s">&#39;green&#39;</span><span class="p">,</span> <span class="s">&#39;Green&#39;</span><span class="p">),</span>
                            <span class="p">(</span><span class="s">&#39;black&#39;</span><span class="p">,</span> <span class="s">&#39;Black&#39;</span><span class="p">))</span>

<span class="k">class</span> <span class="nc">SimpleForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">birth_year</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">DateField</span><span class="p">(</span><span class="n">widget</span><span class="o">=</span><span class="n">SelectDateWidget</span><span class="p">(</span><span class="n">years</span><span class="o">=</span><span class="n">BIRTH_YEAR_CHOICES</span><span class="p">))</span>
    <span class="n">favorite_colors</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">MultipleChoiceField</span><span class="p">(</span><span class="n">required</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
        <span class="n">widget</span><span class="o">=</span><span class="n">forms</span><span class="o">.</span><span class="n">CheckboxSelectMultiple</span><span class="p">,</span> <span class="n">choices</span><span class="o">=</span><span class="n">FAVORITE_COLORS_CHOICES</span><span class="p">)</span>
</pre></div>
</div>
<p>See the <a class="reference internal" href="#built-in-widgets"><em>Built-in widgets</em></a> for more information about which widgets
are available and which arguments they accept.</p>
</div>
<div class="section" id="s-widgets-inheriting-from-the-select-widget">
<span id="widgets-inheriting-from-the-select-widget"></span><h2>Widgets inheriting from the Select widget<a class="headerlink" href="#widgets-inheriting-from-the-select-widget" title="Permalink to this headline">¶</a></h2>
<p>Widgets inheriting from the <a class="reference internal" href="#django.forms.Select" title="django.forms.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> widget deal with choices. They
present the user with a list of options to choose from. The different widgets
present this choice differently; the <a class="reference internal" href="#django.forms.Select" title="django.forms.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> widget itself uses a
<tt class="docutils literal"><span class="pre">&lt;select&gt;</span></tt> HTML list representation, while <a class="reference internal" href="#django.forms.RadioSelect" title="django.forms.RadioSelect"><tt class="xref py py-class docutils literal"><span class="pre">RadioSelect</span></tt></a> uses radio
buttons.</p>
<p><a class="reference internal" href="#django.forms.Select" title="django.forms.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> widgets are used by default on <a class="reference internal" href="fields.html#django.forms.ChoiceField" title="django.forms.ChoiceField"><tt class="xref py py-class docutils literal"><span class="pre">ChoiceField</span></tt></a> fields. The
choices displayed on the widget are inherited from the <a class="reference internal" href="fields.html#django.forms.ChoiceField" title="django.forms.ChoiceField"><tt class="xref py py-class docutils literal"><span class="pre">ChoiceField</span></tt></a> and
changing <a class="reference internal" href="fields.html#django.forms.ChoiceField.choices" title="django.forms.ChoiceField.choices"><tt class="xref py py-attr docutils literal"><span class="pre">ChoiceField.choices</span></tt></a> will update <a class="reference internal" href="#django.forms.Select.choices" title="django.forms.Select.choices"><tt class="xref py py-attr docutils literal"><span class="pre">Select.choices</span></tt></a>. For
example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">CHOICES</span> <span class="o">=</span> <span class="p">((</span><span class="s">&#39;1&#39;</span><span class="p">,</span> <span class="s">&#39;First&#39;</span><span class="p">,),</span> <span class="p">(</span><span class="s">&#39;2&#39;</span><span class="p">,</span> <span class="s">&#39;Second&#39;</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">choice_field</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">ChoiceField</span><span class="p">(</span><span class="n">widget</span><span class="o">=</span><span class="n">forms</span><span class="o">.</span><span class="n">RadioSelect</span><span class="p">,</span> <span class="n">choices</span><span class="o">=</span><span class="n">CHOICES</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">choice_field</span><span class="o">.</span><span class="n">choices</span>
<span class="go">[(&#39;1&#39;, &#39;First&#39;), (&#39;2&#39;, &#39;Second&#39;)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">choice_field</span><span class="o">.</span><span class="n">widget</span><span class="o">.</span><span class="n">choices</span>
<span class="go">[(&#39;1&#39;, &#39;First&#39;), (&#39;2&#39;, &#39;Second&#39;)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">choice_field</span><span class="o">.</span><span class="n">widget</span><span class="o">.</span><span class="n">choices</span> <span class="o">=</span> <span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">choice_field</span><span class="o">.</span><span class="n">choices</span> <span class="o">=</span> <span class="p">((</span><span class="s">&#39;1&#39;</span><span class="p">,</span> <span class="s">&#39;First and only&#39;</span><span class="p">,),)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">choice_field</span><span class="o">.</span><span class="n">widget</span><span class="o">.</span><span class="n">choices</span>
<span class="go">[(&#39;1&#39;, &#39;First and only&#39;)]</span>
</pre></div>
</div>
<p>Widgets which offer a <a class="reference internal" href="#django.forms.Select.choices" title="django.forms.Select.choices"><tt class="xref py py-attr docutils literal"><span class="pre">choices</span></tt></a> attribute can however be used
with fields which are not based on choice &#8211; such as a <a class="reference internal" href="fields.html#django.forms.CharField" title="django.forms.CharField"><tt class="xref py py-class docutils literal"><span class="pre">CharField</span></tt></a> &#8211;
but it is recommended to use a <a class="reference internal" href="fields.html#django.forms.ChoiceField" title="django.forms.ChoiceField"><tt class="xref py py-class docutils literal"><span class="pre">ChoiceField</span></tt></a>-based field when the
choices are inherent to the model and not just the representational widget.</p>
</div>
<div class="section" id="s-customizing-widget-instances">
<span id="customizing-widget-instances"></span><h2>Customizing widget instances<a class="headerlink" href="#customizing-widget-instances" title="Permalink to this headline">¶</a></h2>
<p>When Django renders a widget as HTML, it only renders very minimal markup -
Django doesn&#8217;t add class names, or any other widget-specific attributes. This
means, for example, that all <a class="reference internal" href="#django.forms.TextInput" title="django.forms.TextInput"><tt class="xref py py-class docutils literal"><span class="pre">TextInput</span></tt></a> widgets will appear the same
on your Web pages.</p>
<p>There are two ways to customize widgets: <a class="reference internal" href="#styling-widget-instances"><em>per widget instance</em></a> and <a class="reference internal" href="#styling-widget-classes"><em>per widget class</em></a>.</p>
<div class="section" id="s-styling-widget-instances">
<span id="s-id1"></span><span id="styling-widget-instances"></span><span id="id1"></span><h3>Styling widget instances<a class="headerlink" href="#styling-widget-instances" title="Permalink to this headline">¶</a></h3>
<p>If you want to make one widget instance look different from another, you will
need to specify additional attributes at the time when the widget object is
instantiated and assigned to a form field (and perhaps add some rules to your
CSS files).</p>
<p>For example, take the following simple form:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>

<span class="k">class</span> <span class="nc">CommentForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">()</span>
    <span class="n">url</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">URLField</span><span class="p">()</span>
    <span class="n">comment</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">()</span>
</pre></div>
</div>
<p>This form will include three default <a class="reference internal" href="#django.forms.TextInput" title="django.forms.TextInput"><tt class="xref py py-class docutils literal"><span class="pre">TextInput</span></tt></a> widgets, with default
rendering &#8211; no CSS class, no extra attributes. This means that the input boxes
provided for each widget will be rendered exactly the same:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">CommentForm</span><span class="p">(</span><span class="n">auto_id</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">as_table</span><span class="p">()</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Name:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Url:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;url&quot; name=&quot;url&quot;/&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Comment:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;comment&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;</span>
</pre></div>
</div>
<p>On a real Web page, you probably don&#8217;t want every widget to look the same. You
might want a larger input element for the comment, and you might want the
&#8216;name&#8217; widget to have some special CSS class. It is also possible to specify
the &#8216;type&#8217; attribute to take advantage of the new HTML5 input types.  To do
this, you use the <a class="reference internal" href="#django.forms.Widget.attrs" title="django.forms.Widget.attrs"><tt class="xref py py-attr docutils literal"><span class="pre">Widget.attrs</span></tt></a> argument when creating the widget:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">CommentForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">widget</span><span class="o">=</span><span class="n">forms</span><span class="o">.</span><span class="n">TextInput</span><span class="p">(</span><span class="n">attrs</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;class&#39;</span><span class="p">:</span> <span class="s">&#39;special&#39;</span><span class="p">}))</span>
    <span class="n">url</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">URLField</span><span class="p">()</span>
    <span class="n">comment</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">widget</span><span class="o">=</span><span class="n">forms</span><span class="o">.</span><span class="n">TextInput</span><span class="p">(</span><span class="n">attrs</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;size&#39;</span><span class="p">:</span> <span class="s">&#39;40&#39;</span><span class="p">}))</span>
</pre></div>
</div>
<p>Django will then include the extra attributes in the rendered output:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">CommentForm</span><span class="p">(</span><span class="n">auto_id</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">as_table</span><span class="p">()</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Name:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; class=&quot;special&quot;/&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Url:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;url&quot; name=&quot;url&quot;/&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Comment:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;comment&quot; size=&quot;40&quot;/&gt;&lt;/td&gt;&lt;/tr&gt;</span>
</pre></div>
</div>
<p>You can also set the HTML <tt class="docutils literal"><span class="pre">id</span></tt> using <a class="reference internal" href="#django.forms.Widget.attrs" title="django.forms.Widget.attrs"><tt class="xref py py-attr docutils literal"><span class="pre">attrs</span></tt></a>. See
<a class="reference internal" href="api.html#django.forms.BoundField.id_for_label" title="django.forms.BoundField.id_for_label"><tt class="xref py py-attr docutils literal"><span class="pre">BoundField.id_for_label</span></tt></a> for an example.</p>
</div>
<div class="section" id="s-styling-widget-classes">
<span id="s-id2"></span><span id="styling-widget-classes"></span><span id="id2"></span><h3>Styling widget classes<a class="headerlink" href="#styling-widget-classes" title="Permalink to this headline">¶</a></h3>
<p>With widgets, it is possible to add assets (<tt class="docutils literal"><span class="pre">css</span></tt> and <tt class="docutils literal"><span class="pre">javascript</span></tt>)
and more deeply customize their appearance and behavior.</p>
<p>In a nutshell, you will need to subclass the widget and either
<a class="reference internal" href="../../topics/forms/media.html#assets-as-a-static-definition"><em>define a &#8220;Media&#8221; inner class</em></a> or
<a class="reference internal" href="../../topics/forms/media.html#dynamic-property"><em>create a &#8220;media&#8221; property</em></a>.</p>
<p>These methods involve somewhat advanced Python programming and are described in
detail in the <a class="reference internal" href="../../topics/forms/media.html"><em>Form Assets</em></a> topic guide.</p>
</div>
</div>
<div class="section" id="s-base-widget-classes">
<span id="s-id3"></span><span id="base-widget-classes"></span><span id="id3"></span><h2>Base Widget classes<a class="headerlink" href="#base-widget-classes" title="Permalink to this headline">¶</a></h2>
<p>Base widget classes <a class="reference internal" href="#django.forms.Widget" title="django.forms.Widget"><tt class="xref py py-class docutils literal"><span class="pre">Widget</span></tt></a> and <a class="reference internal" href="#django.forms.MultiWidget" title="django.forms.MultiWidget"><tt class="xref py py-class docutils literal"><span class="pre">MultiWidget</span></tt></a> are subclassed by
all the <a class="reference internal" href="#built-in-widgets"><em>built-in widgets</em></a> and may serve as a
foundation for custom widgets.</p>
<dl class="class">
<dt id="django.forms.Widget">
<em class="property">class </em><tt class="descname">Widget</tt>(<em>attrs=None</em>)<a class="headerlink" href="#django.forms.Widget" title="Permalink to this definition">¶</a></dt>
<dd><p>This abstract class cannot be rendered, but provides the basic attribute
<a class="reference internal" href="#django.forms.Widget.attrs" title="django.forms.Widget.attrs"><tt class="xref py py-attr docutils literal"><span class="pre">attrs</span></tt></a>.  You may also implement or override the
<a class="reference internal" href="#django.forms.Widget.render" title="django.forms.Widget.render"><tt class="xref py py-meth docutils literal"><span class="pre">render()</span></tt></a> method on custom widgets.</p>
<dl class="attribute">
<dt id="django.forms.Widget.attrs">
<tt class="descname">attrs</tt><a class="headerlink" href="#django.forms.Widget.attrs" title="Permalink to this definition">¶</a></dt>
<dd><p>A dictionary containing HTML attributes to be set on the rendered
widget.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">name</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">TextInput</span><span class="p">(</span><span class="n">attrs</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;size&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s">&#39;title&#39;</span><span class="p">:</span> <span class="s">&#39;Your name&#39;</span><span class="p">,})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">name</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="s">&#39;A name&#39;</span><span class="p">)</span>
<span class="go">u&#39;&lt;input title=&quot;Your name&quot; type=&quot;text&quot; name=&quot;name&quot; value=&quot;A name&quot; size=&quot;10&quot; /&gt;&#39;</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.forms.Widget.render">
<tt class="descname">render</tt>(<em>name</em>, <em>value</em>, <em>attrs=None</em>)<a class="headerlink" href="#django.forms.Widget.render" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns HTML for the widget, as a Unicode string. This method must be
implemented by the subclass, otherwise <tt class="docutils literal"><span class="pre">NotImplementedError</span></tt> will be
raised.</p>
<p>The &#8216;value&#8217; given is not guaranteed to be valid input, therefore
subclass implementations should program defensively.</p>
</dd></dl>

<dl class="method">
<dt id="django.forms.Widget.value_from_datadict">
<tt class="descname">value_from_datadict</tt>(<em>data</em>, <em>files</em>, <em>name</em>)<a class="headerlink" href="#django.forms.Widget.value_from_datadict" title="Permalink to this definition">¶</a></dt>
<dd><p>Given a dictionary of data and this widget&#8217;s name, returns the value
of this widget. <tt class="docutils literal"><span class="pre">files</span></tt> may contain data coming from
<a class="reference internal" href="../request-response.html#django.http.HttpRequest.FILES" title="django.http.HttpRequest.FILES"><tt class="xref py py-attr docutils literal"><span class="pre">request.FILES</span></tt></a>. Returns <tt class="docutils literal"><span class="pre">None</span></tt>
if a value wasn&#8217;t provided. Note also that <tt class="docutils literal"><span class="pre">value_from_datadict</span></tt> may
be called more than once during handling of form data, so if you
customize it and add expensive processing, you should implement some
caching mechanism yourself.</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="django.forms.MultiWidget">
<em class="property">class </em><tt class="descname">MultiWidget</tt>(<em>widgets</em>, <em>attrs=None</em>)<a class="headerlink" href="#django.forms.MultiWidget" title="Permalink to this definition">¶</a></dt>
<dd><p>A widget that is composed of multiple widgets.
<a class="reference internal" href="#django.forms.MultiWidget" title="django.forms.MultiWidget"><tt class="xref py py-class docutils literal"><span class="pre">MultiWidget</span></tt></a> works hand in hand with the
<a class="reference internal" href="fields.html#django.forms.MultiValueField" title="django.forms.MultiValueField"><tt class="xref py py-class docutils literal"><span class="pre">MultiValueField</span></tt></a>.</p>
<p><a class="reference internal" href="#django.forms.MultiWidget" title="django.forms.MultiWidget"><tt class="xref py py-class docutils literal"><span class="pre">MultiWidget</span></tt></a> has one required argument:</p>
<dl class="attribute">
<dt id="django.forms.MultiWidget.widgets">
<tt class="descname">widgets</tt><a class="headerlink" href="#django.forms.MultiWidget.widgets" title="Permalink to this definition">¶</a></dt>
<dd><p>An iterable containing the widgets needed.</p>
</dd></dl>

<p>And one required method:</p>
<dl class="method">
<dt id="django.forms.MultiWidget.decompress">
<tt class="descname">decompress</tt>(<em>value</em>)<a class="headerlink" href="#django.forms.MultiWidget.decompress" title="Permalink to this definition">¶</a></dt>
<dd><p>This method takes a single &#8220;compressed&#8221; value from the field and
returns a list of &#8220;decompressed&#8221; values. The input value can be
assumed valid, but not necessarily non-empty.</p>
<p>This method <strong>must be implemented</strong> by the subclass, and since the
value may be empty, the implementation must be defensive.</p>
<p>The rationale behind &#8220;decompression&#8221; is that it is necessary to &#8220;split&#8221;
the combined value of the form field into the values for each widget.</p>
<p>An example of this is how <a class="reference internal" href="#django.forms.SplitDateTimeWidget" title="django.forms.SplitDateTimeWidget"><tt class="xref py py-class docutils literal"><span class="pre">SplitDateTimeWidget</span></tt></a> turns a
<a class="reference external" href="http://docs.python.org/3/library/datetime.html#datetime.datetime" title="(in Python v3.4)"><tt class="xref py py-class docutils literal"><span class="pre">datetime</span></tt></a> value into a list with date and time split
into two separate values:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.forms</span> <span class="kn">import</span> <span class="n">MultiWidget</span>

<span class="k">class</span> <span class="nc">SplitDateTimeWidget</span><span class="p">(</span><span class="n">MultiWidget</span><span class="p">):</span>

    <span class="c"># ...</span>

    <span class="k">def</span> <span class="nf">decompress</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">value</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="n">value</span><span class="o">.</span><span class="n">date</span><span class="p">(),</span> <span class="n">value</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">microsecond</span><span class="o">=</span><span class="mi">0</span><span class="p">)]</span>
        <span class="k">return</span> <span class="p">[</span><span class="bp">None</span><span class="p">,</span> <span class="bp">None</span><span class="p">]</span>
</pre></div>
</div>
<div class="admonition tip">
<p class="first admonition-title">Tip</p>
<p class="last">Note that <a class="reference internal" href="fields.html#django.forms.MultiValueField" title="django.forms.MultiValueField"><tt class="xref py py-class docutils literal"><span class="pre">MultiValueField</span></tt></a> has a
complementary method <a class="reference internal" href="fields.html#django.forms.MultiValueField.compress" title="django.forms.MultiValueField.compress"><tt class="xref py py-meth docutils literal"><span class="pre">compress()</span></tt></a>
with the opposite responsibility - to combine cleaned values of
all member fields into one.</p>
</div>
</dd></dl>

<p>Other methods that may be useful to override include:</p>
<dl class="method">
<dt id="django.forms.MultiWidget.render">
<tt class="descname">render</tt>(<em>name</em>, <em>value</em>, <em>attrs=None</em>)<a class="headerlink" href="#django.forms.MultiWidget.render" title="Permalink to this definition">¶</a></dt>
<dd><p>Argument <tt class="docutils literal"><span class="pre">value</span></tt> is handled differently in this method from the
subclasses of <a class="reference internal" href="#django.forms.Widget" title="django.forms.Widget"><tt class="xref py py-class docutils literal"><span class="pre">Widget</span></tt></a> because it has to figure out how to
split a single value for display in multiple widgets.</p>
<p>The <tt class="docutils literal"><span class="pre">value</span></tt> argument used when rendering can be one of two things:</p>
<ul class="simple">
<li>A <tt class="docutils literal"><span class="pre">list</span></tt>.</li>
<li>A single value (e.g., a string) that is the &#8220;compressed&#8221; representation
of a <tt class="docutils literal"><span class="pre">list</span></tt> of values.</li>
</ul>
<p>If <tt class="docutils literal"><span class="pre">value</span></tt> is a list, the output of <a class="reference internal" href="#django.forms.MultiWidget.render" title="django.forms.MultiWidget.render"><tt class="xref py py-meth docutils literal"><span class="pre">render()</span></tt></a> will
be a concatenation of rendered child widgets. If <tt class="docutils literal"><span class="pre">value</span></tt> is not a
list, it will first be processed by the method
<a class="reference internal" href="#django.forms.MultiWidget.decompress" title="django.forms.MultiWidget.decompress"><tt class="xref py py-meth docutils literal"><span class="pre">decompress()</span></tt></a> to create the list and then rendered.</p>
<p>When <tt class="docutils literal"><span class="pre">render()</span></tt> executes its HTML rendering, each value in the list
is rendered with the corresponding widget &#8211; the first value is
rendered in the first widget, the second value is rendered in the
second widget, etc.</p>
<p>Unlike in the single value widgets, method <a class="reference internal" href="#django.forms.MultiWidget.render" title="django.forms.MultiWidget.render"><tt class="xref py py-meth docutils literal"><span class="pre">render()</span></tt></a>
need not be implemented in the subclasses.</p>
</dd></dl>

<dl class="method">
<dt id="django.forms.MultiWidget.format_output">
<tt class="descname">format_output</tt>(<em>rendered_widgets</em>)<a class="headerlink" href="#django.forms.MultiWidget.format_output" title="Permalink to this definition">¶</a></dt>
<dd><p>Given a list of rendered widgets (as strings), returns a Unicode string
representing the HTML for the whole lot.</p>
<p>This hook allows you to format the HTML design of the widgets any way
you&#8217;d like.</p>
</dd></dl>

<p>Here&#8217;s an example widget which subclasses <a class="reference internal" href="#django.forms.MultiWidget" title="django.forms.MultiWidget"><tt class="xref py py-class docutils literal"><span class="pre">MultiWidget</span></tt></a> to display
a date with the day, month, and year in different select boxes. This widget
is intended to be used with a <a class="reference internal" href="fields.html#django.forms.DateField" title="django.forms.DateField"><tt class="xref py py-class docutils literal"><span class="pre">DateField</span></tt></a> rather than
a <a class="reference internal" href="fields.html#django.forms.MultiValueField" title="django.forms.MultiValueField"><tt class="xref py py-class docutils literal"><span class="pre">MultiValueField</span></tt></a>, thus we have implemented
<a class="reference internal" href="#django.forms.Widget.value_from_datadict" title="django.forms.Widget.value_from_datadict"><tt class="xref py py-meth docutils literal"><span class="pre">value_from_datadict()</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">date</span>
<span class="kn">from</span> <span class="nn">django.forms</span> <span class="kn">import</span> <span class="n">widgets</span>

<span class="k">class</span> <span class="nc">DateSelectorWidget</span><span class="p">(</span><span class="n">widgets</span><span class="o">.</span><span class="n">MultiWidget</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attrs</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="c"># create choices for days, months, years</span>
        <span class="c"># example below, the rest snipped for brevity.</span>
        <span class="n">years</span> <span class="o">=</span> <span class="p">[(</span><span class="n">year</span><span class="p">,</span> <span class="n">year</span><span class="p">)</span> <span class="k">for</span> <span class="n">year</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">2011</span><span class="p">,</span> <span class="mi">2012</span><span class="p">,</span> <span class="mi">2013</span><span class="p">)]</span>
        <span class="n">_widgets</span> <span class="o">=</span> <span class="p">(</span>
            <span class="n">widgets</span><span class="o">.</span><span class="n">Select</span><span class="p">(</span><span class="n">attrs</span><span class="o">=</span><span class="n">attrs</span><span class="p">,</span> <span class="n">choices</span><span class="o">=</span><span class="n">days</span><span class="p">),</span>
            <span class="n">widgets</span><span class="o">.</span><span class="n">Select</span><span class="p">(</span><span class="n">attrs</span><span class="o">=</span><span class="n">attrs</span><span class="p">,</span> <span class="n">choices</span><span class="o">=</span><span class="n">months</span><span class="p">),</span>
            <span class="n">widgets</span><span class="o">.</span><span class="n">Select</span><span class="p">(</span><span class="n">attrs</span><span class="o">=</span><span class="n">attrs</span><span class="p">,</span> <span class="n">choices</span><span class="o">=</span><span class="n">years</span><span class="p">),</span>
        <span class="p">)</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">DateSelectorWidget</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">_widgets</span><span class="p">,</span> <span class="n">attrs</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">decompress</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">value</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="n">value</span><span class="o">.</span><span class="n">day</span><span class="p">,</span> <span class="n">value</span><span class="o">.</span><span class="n">month</span><span class="p">,</span> <span class="n">value</span><span class="o">.</span><span class="n">year</span><span class="p">]</span>
        <span class="k">return</span> <span class="p">[</span><span class="bp">None</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span> <span class="bp">None</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">format_output</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rendered_widgets</span><span class="p">):</span>
        <span class="k">return</span> <span class="s">u&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">rendered_widgets</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">value_from_datadict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">files</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="n">datelist</span> <span class="o">=</span> <span class="p">[</span>
            <span class="n">widget</span><span class="o">.</span><span class="n">value_from_datadict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">files</span><span class="p">,</span> <span class="n">name</span> <span class="o">+</span> <span class="s">&#39;_</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">i</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">widget</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">widgets</span><span class="p">)]</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">D</span> <span class="o">=</span> <span class="n">date</span><span class="p">(</span><span class="n">day</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">datelist</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="n">month</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">datelist</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                    <span class="n">year</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">datelist</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="k">return</span> <span class="s">&#39;&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="n">D</span><span class="p">)</span>
</pre></div>
</div>
<p>The constructor creates several <a class="reference internal" href="#django.forms.Select" title="django.forms.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> widgets in a tuple. The
<tt class="docutils literal"><span class="pre">super</span></tt> class uses this tuple to setup the widget.</p>
<p>The <a class="reference internal" href="#django.forms.MultiWidget.format_output" title="django.forms.MultiWidget.format_output"><tt class="xref py py-meth docutils literal"><span class="pre">format_output()</span></tt></a> method is fairly vanilla here (in
fact, it&#8217;s the same as what&#8217;s been implemented as the default for
<tt class="docutils literal"><span class="pre">MultiWidget</span></tt>), but the idea is that you could add custom HTML between
the widgets should you wish.</p>
<p>The required method <a class="reference internal" href="#django.forms.MultiWidget.decompress" title="django.forms.MultiWidget.decompress"><tt class="xref py py-meth docutils literal"><span class="pre">decompress()</span></tt></a> breaks up a
<tt class="docutils literal"><span class="pre">datetime.date</span></tt> value into the day, month, and year values corresponding
to each widget. Note how the method handles the case where <tt class="docutils literal"><span class="pre">value</span></tt> is
<tt class="docutils literal"><span class="pre">None</span></tt>.</p>
<p>The default implementation of <a class="reference internal" href="#django.forms.Widget.value_from_datadict" title="django.forms.Widget.value_from_datadict"><tt class="xref py py-meth docutils literal"><span class="pre">value_from_datadict()</span></tt></a> returns
a list of values corresponding to each <tt class="docutils literal"><span class="pre">Widget</span></tt>.  This is appropriate
when using a <tt class="docutils literal"><span class="pre">MultiWidget</span></tt> with a <a class="reference internal" href="fields.html#django.forms.MultiValueField" title="django.forms.MultiValueField"><tt class="xref py py-class docutils literal"><span class="pre">MultiValueField</span></tt></a>,
but since we want to use this widget with a <a class="reference internal" href="fields.html#django.forms.DateField" title="django.forms.DateField"><tt class="xref py py-class docutils literal"><span class="pre">DateField</span></tt></a>
which takes a single value, we have overridden this method to combine the
data of all the subwidgets into a <tt class="docutils literal"><span class="pre">datetime.date</span></tt>. The method extracts
data from the <tt class="docutils literal"><span class="pre">POST</span></tt> dictionary and constructs and validates the date.
If it is valid, we return the string, otherwise, we return an empty string
which will cause <tt class="docutils literal"><span class="pre">form.is_valid</span></tt> to return <tt class="docutils literal"><span class="pre">False</span></tt>.</p>
</dd></dl>

</div>
<div class="section" id="s-built-in-widgets">
<span id="s-id4"></span><span id="built-in-widgets"></span><span id="id4"></span><h2>Built-in widgets<a class="headerlink" href="#built-in-widgets" title="Permalink to this headline">¶</a></h2>
<p>Django provides a representation of all the basic HTML widgets, plus some
commonly used groups of widgets in the <tt class="docutils literal"><span class="pre">django.forms.widgets</span></tt> module,
including <a class="reference internal" href="#text-widgets"><em>the input of text</em></a>, <a class="reference internal" href="#selector-widgets"><em>various checkboxes
and selectors</em></a>, <a class="reference internal" href="#file-upload-widgets"><em>uploading files</em></a>,
and <a class="reference internal" href="#composite-widgets"><em>handling of multi-valued input</em></a>.</p>
<div class="section" id="s-widgets-handling-input-of-text">
<span id="s-text-widgets"></span><span id="widgets-handling-input-of-text"></span><span id="text-widgets"></span><h3>Widgets handling input of text<a class="headerlink" href="#widgets-handling-input-of-text" title="Permalink to this headline">¶</a></h3>
<p>These widgets make use of the HTML elements <tt class="docutils literal"><span class="pre">input</span></tt> and <tt class="docutils literal"><span class="pre">textarea</span></tt>.</p>
<div class="section" id="s-textinput">
<span id="textinput"></span><h4><tt class="docutils literal"><span class="pre">TextInput</span></tt><a class="headerlink" href="#textinput" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.TextInput">
<em class="property">class </em><tt class="descname">TextInput</tt><a class="headerlink" href="#django.forms.TextInput" title="Permalink to this definition">¶</a></dt>
<dd><p>Text input: <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type=&quot;text&quot;</span> <span class="pre">...&gt;</span></tt></p>
</dd></dl>

</div>
<div class="section" id="s-numberinput">
<span id="numberinput"></span><h4><tt class="docutils literal"><span class="pre">NumberInput</span></tt><a class="headerlink" href="#numberinput" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.NumberInput">
<em class="property">class </em><tt class="descname">NumberInput</tt><a class="headerlink" href="#django.forms.NumberInput" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.6.</span> </div>
<p>Text input: <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type=&quot;number&quot;</span> <span class="pre">...&gt;</span></tt></p>
<p>Beware that not all browsers support entering localized numbers in
<tt class="docutils literal"><span class="pre">number</span></tt> input types. Django itself avoids using them for fields having
their <a class="reference internal" href="fields.html#django.forms.Field.localize" title="django.forms.Field.localize"><tt class="xref py py-attr docutils literal"><span class="pre">localize</span></tt></a> property to <tt class="docutils literal"><span class="pre">True</span></tt>.</p>
</dd></dl>

</div>
<div class="section" id="s-emailinput">
<span id="emailinput"></span><h4><tt class="docutils literal"><span class="pre">EmailInput</span></tt><a class="headerlink" href="#emailinput" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.EmailInput">
<em class="property">class </em><tt class="descname">EmailInput</tt><a class="headerlink" href="#django.forms.EmailInput" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.6.</span> </div>
<p>Text input: <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type=&quot;email&quot;</span> <span class="pre">...&gt;</span></tt></p>
</dd></dl>

</div>
<div class="section" id="s-urlinput">
<span id="urlinput"></span><h4><tt class="docutils literal"><span class="pre">URLInput</span></tt><a class="headerlink" href="#urlinput" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.URLInput">
<em class="property">class </em><tt class="descname">URLInput</tt><a class="headerlink" href="#django.forms.URLInput" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.6.</span> </div>
<p>Text input: <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type=&quot;url&quot;</span> <span class="pre">...&gt;</span></tt></p>
</dd></dl>

</div>
<div class="section" id="s-passwordinput">
<span id="passwordinput"></span><h4><tt class="docutils literal"><span class="pre">PasswordInput</span></tt><a class="headerlink" href="#passwordinput" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.PasswordInput">
<em class="property">class </em><tt class="descname">PasswordInput</tt><a class="headerlink" href="#django.forms.PasswordInput" title="Permalink to this definition">¶</a></dt>
<dd><p>Password input: <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type='password'</span> <span class="pre">...&gt;</span></tt></p>
<p>Takes one optional argument:</p>
<dl class="attribute">
<dt id="django.forms.PasswordInput.render_value">
<tt class="descname">render_value</tt><a class="headerlink" href="#django.forms.PasswordInput.render_value" title="Permalink to this definition">¶</a></dt>
<dd><p>Determines whether the widget will have a value filled in when the
form is re-displayed after a validation error (default is <tt class="docutils literal"><span class="pre">False</span></tt>).</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-hiddeninput">
<span id="hiddeninput"></span><h4><tt class="docutils literal"><span class="pre">HiddenInput</span></tt><a class="headerlink" href="#hiddeninput" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.HiddenInput">
<em class="property">class </em><tt class="descname">HiddenInput</tt><a class="headerlink" href="#django.forms.HiddenInput" title="Permalink to this definition">¶</a></dt>
<dd><p>Hidden input: <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type='hidden'</span> <span class="pre">...&gt;</span></tt></p>
<p>Note that there also is a <a class="reference internal" href="#django.forms.MultipleHiddenInput" title="django.forms.MultipleHiddenInput"><tt class="xref py py-class docutils literal"><span class="pre">MultipleHiddenInput</span></tt></a> widget that
encapsulates a set of hidden input elements.</p>
</dd></dl>

</div>
<div class="section" id="s-dateinput">
<span id="dateinput"></span><h4><tt class="docutils literal"><span class="pre">DateInput</span></tt><a class="headerlink" href="#dateinput" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.DateInput">
<em class="property">class </em><tt class="descname">DateInput</tt><a class="headerlink" href="#django.forms.DateInput" title="Permalink to this definition">¶</a></dt>
<dd><p>Date input as a simple text box: <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type='text'</span> <span class="pre">...&gt;</span></tt></p>
<p>Takes same arguments as <a class="reference internal" href="#django.forms.TextInput" title="django.forms.TextInput"><tt class="xref py py-class docutils literal"><span class="pre">TextInput</span></tt></a>, with one more optional argument:</p>
<dl class="attribute">
<dt id="django.forms.DateInput.format">
<tt class="descname">format</tt><a class="headerlink" href="#django.forms.DateInput.format" title="Permalink to this definition">¶</a></dt>
<dd><p>The format in which this field&#8217;s initial value will be displayed.</p>
</dd></dl>

<p>If no <tt class="docutils literal"><span class="pre">format</span></tt> argument is provided, the default format is the first
format found in <a class="reference internal" href="../settings.html#std:setting-DATE_INPUT_FORMATS"><tt class="xref std std-setting docutils literal"><span class="pre">DATE_INPUT_FORMATS</span></tt></a> and respects
<a class="reference internal" href="../../topics/i18n/formatting.html#format-localization"><em>Format localization</em></a>.</p>
</dd></dl>

</div>
<div class="section" id="s-datetimeinput">
<span id="datetimeinput"></span><h4><tt class="docutils literal"><span class="pre">DateTimeInput</span></tt><a class="headerlink" href="#datetimeinput" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.DateTimeInput">
<em class="property">class </em><tt class="descname">DateTimeInput</tt><a class="headerlink" href="#django.forms.DateTimeInput" title="Permalink to this definition">¶</a></dt>
<dd><p>Date/time input as a simple text box: <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type='text'</span> <span class="pre">...&gt;</span></tt></p>
<p>Takes same arguments as <a class="reference internal" href="#django.forms.TextInput" title="django.forms.TextInput"><tt class="xref py py-class docutils literal"><span class="pre">TextInput</span></tt></a>, with one more optional argument:</p>
<dl class="attribute">
<dt id="django.forms.DateTimeInput.format">
<tt class="descname">format</tt><a class="headerlink" href="#django.forms.DateTimeInput.format" title="Permalink to this definition">¶</a></dt>
<dd><p>The format in which this field&#8217;s initial value will be displayed.</p>
</dd></dl>

<p>If no <tt class="docutils literal"><span class="pre">format</span></tt> argument is provided, the default format is the first
format found in <a class="reference internal" href="../settings.html#std:setting-DATETIME_INPUT_FORMATS"><tt class="xref std std-setting docutils literal"><span class="pre">DATETIME_INPUT_FORMATS</span></tt></a> and respects
<a class="reference internal" href="../../topics/i18n/formatting.html#format-localization"><em>Format localization</em></a>.</p>
</dd></dl>

</div>
<div class="section" id="s-timeinput">
<span id="timeinput"></span><h4><tt class="docutils literal"><span class="pre">TimeInput</span></tt><a class="headerlink" href="#timeinput" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.TimeInput">
<em class="property">class </em><tt class="descname">TimeInput</tt><a class="headerlink" href="#django.forms.TimeInput" title="Permalink to this definition">¶</a></dt>
<dd><p>Time input as a simple text box: <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type='text'</span> <span class="pre">...&gt;</span></tt></p>
<p>Takes same arguments as <a class="reference internal" href="#django.forms.TextInput" title="django.forms.TextInput"><tt class="xref py py-class docutils literal"><span class="pre">TextInput</span></tt></a>, with one more optional argument:</p>
<dl class="attribute">
<dt id="django.forms.TimeInput.format">
<tt class="descname">format</tt><a class="headerlink" href="#django.forms.TimeInput.format" title="Permalink to this definition">¶</a></dt>
<dd><p>The format in which this field&#8217;s initial value will be displayed.</p>
</dd></dl>

<p>If no <tt class="docutils literal"><span class="pre">format</span></tt> argument is provided, the default format is the first
format found in <a class="reference internal" href="../settings.html#std:setting-TIME_INPUT_FORMATS"><tt class="xref std std-setting docutils literal"><span class="pre">TIME_INPUT_FORMATS</span></tt></a> and respects
<a class="reference internal" href="../../topics/i18n/formatting.html#format-localization"><em>Format localization</em></a>.</p>
</dd></dl>

</div>
<div class="section" id="s-textarea">
<span id="textarea"></span><h4><tt class="docutils literal"><span class="pre">Textarea</span></tt><a class="headerlink" href="#textarea" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.Textarea">
<em class="property">class </em><tt class="descname">Textarea</tt><a class="headerlink" href="#django.forms.Textarea" title="Permalink to this definition">¶</a></dt>
<dd><p>Text area: <tt class="docutils literal"><span class="pre">&lt;textarea&gt;...&lt;/textarea&gt;</span></tt></p>
</dd></dl>

</div>
</div>
<div class="section" id="s-selector-and-checkbox-widgets">
<span id="s-selector-widgets"></span><span id="selector-and-checkbox-widgets"></span><span id="selector-widgets"></span><h3>Selector and checkbox widgets<a class="headerlink" href="#selector-and-checkbox-widgets" title="Permalink to this headline">¶</a></h3>
<div class="section" id="s-checkboxinput">
<span id="checkboxinput"></span><h4><tt class="docutils literal"><span class="pre">CheckboxInput</span></tt><a class="headerlink" href="#checkboxinput" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.CheckboxInput">
<em class="property">class </em><tt class="descname">CheckboxInput</tt><a class="headerlink" href="#django.forms.CheckboxInput" title="Permalink to this definition">¶</a></dt>
<dd><p>Checkbox: <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type='checkbox'</span> <span class="pre">...&gt;</span></tt></p>
<p>Takes one optional argument:</p>
<dl class="attribute">
<dt id="django.forms.CheckboxInput.check_test">
<tt class="descname">check_test</tt><a class="headerlink" href="#django.forms.CheckboxInput.check_test" title="Permalink to this definition">¶</a></dt>
<dd><p>A callable that takes the value of the <tt class="docutils literal"><span class="pre">CheckboxInput</span></tt> and returns
<tt class="docutils literal"><span class="pre">True</span></tt> if the checkbox should be checked for that value.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-select">
<span id="select"></span><h4><tt class="docutils literal"><span class="pre">Select</span></tt><a class="headerlink" href="#select" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.Select">
<em class="property">class </em><tt class="descname">Select</tt><a class="headerlink" href="#django.forms.Select" title="Permalink to this definition">¶</a></dt>
<dd><p>Select widget: <tt class="docutils literal"><span class="pre">&lt;select&gt;&lt;option</span> <span class="pre">...&gt;...&lt;/select&gt;</span></tt></p>
<dl class="attribute">
<dt id="django.forms.Select.choices">
<tt class="descname">choices</tt><a class="headerlink" href="#django.forms.Select.choices" title="Permalink to this definition">¶</a></dt>
<dd><p>This attribute is optional when the form field does not have a
<tt class="docutils literal"><span class="pre">choices</span></tt> attribute. If it does, it will override anything you set
here when the attribute is updated on the <a class="reference internal" href="fields.html#django.forms.Field" title="django.forms.Field"><tt class="xref py py-class docutils literal"><span class="pre">Field</span></tt></a>.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-nullbooleanselect">
<span id="nullbooleanselect"></span><h4><tt class="docutils literal"><span class="pre">NullBooleanSelect</span></tt><a class="headerlink" href="#nullbooleanselect" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.NullBooleanSelect">
<em class="property">class </em><tt class="descname">NullBooleanSelect</tt><a class="headerlink" href="#django.forms.NullBooleanSelect" title="Permalink to this definition">¶</a></dt>
<dd><p>Select widget with options &#8216;Unknown&#8217;, &#8216;Yes&#8217; and &#8216;No&#8217;</p>
</dd></dl>

</div>
<div class="section" id="s-selectmultiple">
<span id="selectmultiple"></span><h4><tt class="docutils literal"><span class="pre">SelectMultiple</span></tt><a class="headerlink" href="#selectmultiple" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.SelectMultiple">
<em class="property">class </em><tt class="descname">SelectMultiple</tt><a class="headerlink" href="#django.forms.SelectMultiple" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#django.forms.Select" title="django.forms.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>, but allows multiple selection:
<tt class="docutils literal"><span class="pre">&lt;select</span> <span class="pre">multiple='multiple'&gt;...&lt;/select&gt;</span></tt></p>
</dd></dl>

</div>
<div class="section" id="s-radioselect">
<span id="radioselect"></span><h4><tt class="docutils literal"><span class="pre">RadioSelect</span></tt><a class="headerlink" href="#radioselect" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.RadioSelect">
<em class="property">class </em><tt class="descname">RadioSelect</tt><a class="headerlink" href="#django.forms.RadioSelect" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#django.forms.Select" title="django.forms.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>, but rendered as a list of radio buttons within
<tt class="docutils literal"><span class="pre">&lt;li&gt;</span></tt> tags:</p>
<div class="highlight-html"><div class="highlight"><pre><span class="nt">&lt;ul&gt;</span>
  <span class="nt">&lt;li&gt;&lt;input</span> <span class="na">type=</span><span class="s">&#39;radio&#39;</span> <span class="na">name=</span><span class="s">&#39;...&#39;</span><span class="nt">&gt;&lt;/li&gt;</span>
  ...
<span class="nt">&lt;/ul&gt;</span>
</pre></div>
</div>
<p>For more granular control over the generated markup, you can loop over the
radio buttons in the template. Assuming a form <tt class="docutils literal"><span class="pre">myform</span></tt> with a field
<tt class="docutils literal"><span class="pre">beatles</span></tt> that uses a <tt class="docutils literal"><span class="pre">RadioSelect</span></tt> as its widget:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">for</span> <span class="nv">radio</span> <span class="k">in</span> <span class="nv">myform.beatles</span> <span class="cp">%}</span>
<span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;myradio&quot;</span><span class="nt">&gt;</span>
    <span class="cp">{{</span> <span class="nv">radio</span> <span class="cp">}}</span>
<span class="nt">&lt;/div&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>This would generate the following HTML:</p>
<div class="highlight-html"><div class="highlight"><pre><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;myradio&quot;</span><span class="nt">&gt;</span>
    <span class="nt">&lt;label</span> <span class="na">for=</span><span class="s">&quot;id_beatles_0&quot;</span><span class="nt">&gt;&lt;input</span> <span class="na">id=</span><span class="s">&quot;id_beatles_0&quot;</span> <span class="na">name=</span><span class="s">&quot;beatles&quot;</span> <span class="na">type=</span><span class="s">&quot;radio&quot;</span> <span class="na">value=</span><span class="s">&quot;john&quot;</span> <span class="nt">/&gt;</span> John<span class="nt">&lt;/label&gt;</span>
<span class="nt">&lt;/div&gt;</span>
<span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;myradio&quot;</span><span class="nt">&gt;</span>
    <span class="nt">&lt;label</span> <span class="na">for=</span><span class="s">&quot;id_beatles_1&quot;</span><span class="nt">&gt;&lt;input</span> <span class="na">id=</span><span class="s">&quot;id_beatles_1&quot;</span> <span class="na">name=</span><span class="s">&quot;beatles&quot;</span> <span class="na">type=</span><span class="s">&quot;radio&quot;</span> <span class="na">value=</span><span class="s">&quot;paul&quot;</span> <span class="nt">/&gt;</span> Paul<span class="nt">&lt;/label&gt;</span>
<span class="nt">&lt;/div&gt;</span>
<span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;myradio&quot;</span><span class="nt">&gt;</span>
    <span class="nt">&lt;label</span> <span class="na">for=</span><span class="s">&quot;id_beatles_2&quot;</span><span class="nt">&gt;&lt;input</span> <span class="na">id=</span><span class="s">&quot;id_beatles_2&quot;</span> <span class="na">name=</span><span class="s">&quot;beatles&quot;</span> <span class="na">type=</span><span class="s">&quot;radio&quot;</span> <span class="na">value=</span><span class="s">&quot;george&quot;</span> <span class="nt">/&gt;</span> George<span class="nt">&lt;/label&gt;</span>
<span class="nt">&lt;/div&gt;</span>
<span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;myradio&quot;</span><span class="nt">&gt;</span>
    <span class="nt">&lt;label</span> <span class="na">for=</span><span class="s">&quot;id_beatles_3&quot;</span><span class="nt">&gt;&lt;input</span> <span class="na">id=</span><span class="s">&quot;id_beatles_3&quot;</span> <span class="na">name=</span><span class="s">&quot;beatles&quot;</span> <span class="na">type=</span><span class="s">&quot;radio&quot;</span> <span class="na">value=</span><span class="s">&quot;ringo&quot;</span> <span class="nt">/&gt;</span> Ringo<span class="nt">&lt;/label&gt;</span>
<span class="nt">&lt;/div&gt;</span>
</pre></div>
</div>
<p>That included the <tt class="docutils literal"><span class="pre">&lt;label&gt;</span></tt> tags. To get more granular, you can use each
radio button&#8217;s <tt class="docutils literal"><span class="pre">tag</span></tt>, <tt class="docutils literal"><span class="pre">choice_label</span></tt> and <tt class="docutils literal"><span class="pre">id_for_label</span></tt> attributes.
For example, this template...</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">for</span> <span class="nv">radio</span> <span class="k">in</span> <span class="nv">myform.beatles</span> <span class="cp">%}</span>
    <span class="nt">&lt;label</span> <span class="na">for=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">radio.id_for_label</span> <span class="cp">}}</span><span class="s">&quot;</span><span class="nt">&gt;</span>
        <span class="cp">{{</span> <span class="nv">radio.choice_label</span> <span class="cp">}}</span>
        <span class="nt">&lt;span</span> <span class="na">class=</span><span class="s">&quot;radio&quot;</span><span class="nt">&gt;</span><span class="cp">{{</span> <span class="nv">radio.tag</span> <span class="cp">}}</span><span class="nt">&lt;/span&gt;</span>
    <span class="nt">&lt;/label&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>...will result in the following HTML:</p>
<div class="highlight-html"><div class="highlight"><pre><span class="nt">&lt;label</span> <span class="na">for=</span><span class="s">&quot;id_beatles_0&quot;</span><span class="nt">&gt;</span>
    John
    <span class="nt">&lt;span</span> <span class="na">class=</span><span class="s">&quot;radio&quot;</span><span class="nt">&gt;&lt;input</span> <span class="na">id=</span><span class="s">&quot;id_beatles_0&quot;</span> <span class="na">name=</span><span class="s">&quot;beatles&quot;</span> <span class="na">type=</span><span class="s">&quot;radio&quot;</span> <span class="na">value=</span><span class="s">&quot;john&quot;</span> <span class="nt">/&gt;&lt;/span&gt;</span>
<span class="nt">&lt;/label&gt;</span>

<span class="nt">&lt;label</span> <span class="na">for=</span><span class="s">&quot;id_beatles_1&quot;</span><span class="nt">&gt;</span>
    Paul
    <span class="nt">&lt;span</span> <span class="na">class=</span><span class="s">&quot;radio&quot;</span><span class="nt">&gt;&lt;input</span> <span class="na">id=</span><span class="s">&quot;id_beatles_1&quot;</span> <span class="na">name=</span><span class="s">&quot;beatles&quot;</span> <span class="na">type=</span><span class="s">&quot;radio&quot;</span> <span class="na">value=</span><span class="s">&quot;paul&quot;</span> <span class="nt">/&gt;&lt;/span&gt;</span>
<span class="nt">&lt;/label&gt;</span>

<span class="nt">&lt;label</span> <span class="na">for=</span><span class="s">&quot;id_beatles_2&quot;</span><span class="nt">&gt;</span>
    George
    <span class="nt">&lt;span</span> <span class="na">class=</span><span class="s">&quot;radio&quot;</span><span class="nt">&gt;&lt;input</span> <span class="na">id=</span><span class="s">&quot;id_beatles_2&quot;</span> <span class="na">name=</span><span class="s">&quot;beatles&quot;</span> <span class="na">type=</span><span class="s">&quot;radio&quot;</span> <span class="na">value=</span><span class="s">&quot;george&quot;</span> <span class="nt">/&gt;&lt;/span&gt;</span>
<span class="nt">&lt;/label&gt;</span>

<span class="nt">&lt;label</span> <span class="na">for=</span><span class="s">&quot;id_beatles_3&quot;</span><span class="nt">&gt;</span>
    Ringo
    <span class="nt">&lt;span</span> <span class="na">class=</span><span class="s">&quot;radio&quot;</span><span class="nt">&gt;&lt;input</span> <span class="na">id=</span><span class="s">&quot;id_beatles_3&quot;</span> <span class="na">name=</span><span class="s">&quot;beatles&quot;</span> <span class="na">type=</span><span class="s">&quot;radio&quot;</span> <span class="na">value=</span><span class="s">&quot;ringo&quot;</span> <span class="nt">/&gt;&lt;/span&gt;</span>
<span class="nt">&lt;/label&gt;</span>
</pre></div>
</div>
<p>If you decide not to loop over the radio buttons &#8211; e.g., if your template
simply includes <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">myform.beatles</span> <span class="pre">}}</span></tt> &#8211; they&#8217;ll be output in a <tt class="docutils literal"><span class="pre">&lt;ul&gt;</span></tt>
with <tt class="docutils literal"><span class="pre">&lt;li&gt;</span></tt> tags, as above.</p>
</dd></dl>

<div class="versionchanged">
<span class="title">Changed in Django 1.6.</span> </div>
<p>The outer <tt class="docutils literal"><span class="pre">&lt;ul&gt;</span></tt> container will now receive the <tt class="docutils literal"><span class="pre">id</span></tt> attribute defined on
the widget.</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.7:</span> <p>When looping over the radio buttons, the <tt class="docutils literal"><span class="pre">label</span></tt> and <tt class="docutils literal"><span class="pre">input</span></tt> tags include
<tt class="docutils literal"><span class="pre">for</span></tt> and <tt class="docutils literal"><span class="pre">id</span></tt> attributes, respectively. Each radio button has an
<tt class="docutils literal"><span class="pre">id_for_label</span></tt> attribute to output the element&#8217;s ID.</p>
</div>
</div>
<div class="section" id="s-checkboxselectmultiple">
<span id="checkboxselectmultiple"></span><h4><tt class="docutils literal"><span class="pre">CheckboxSelectMultiple</span></tt><a class="headerlink" href="#checkboxselectmultiple" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.CheckboxSelectMultiple">
<em class="property">class </em><tt class="descname">CheckboxSelectMultiple</tt><a class="headerlink" href="#django.forms.CheckboxSelectMultiple" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#django.forms.SelectMultiple" title="django.forms.SelectMultiple"><tt class="xref py py-class docutils literal"><span class="pre">SelectMultiple</span></tt></a>, but rendered as a list of check
buttons:</p>
<div class="highlight-html"><div class="highlight"><pre><span class="nt">&lt;ul&gt;</span>
  <span class="nt">&lt;li&gt;&lt;input</span> <span class="na">type=</span><span class="s">&#39;checkbox&#39;</span> <span class="na">name=</span><span class="s">&#39;...&#39;</span> <span class="nt">&gt;&lt;/li&gt;</span>
  ...
<span class="nt">&lt;/ul&gt;</span>
</pre></div>
</div>
</dd></dl>

<div class="versionchanged">
<span class="title">Changed in Django 1.6.</span> </div>
<p>The outer <tt class="docutils literal"><span class="pre">&lt;ul&gt;</span></tt> container will now receive the <tt class="docutils literal"><span class="pre">id</span></tt> attribute defined on
the widget.</p>
<p>Like <a class="reference internal" href="#django.forms.RadioSelect" title="django.forms.RadioSelect"><tt class="xref py py-class docutils literal"><span class="pre">RadioSelect</span></tt></a>, you can now loop over the individual checkboxes making
up the lists. See the documentation of <a class="reference internal" href="#django.forms.RadioSelect" title="django.forms.RadioSelect"><tt class="xref py py-class docutils literal"><span class="pre">RadioSelect</span></tt></a> for more details.</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.7:</span> <p>When looping over the checkboxes, the <tt class="docutils literal"><span class="pre">label</span></tt> and <tt class="docutils literal"><span class="pre">input</span></tt> tags include
<tt class="docutils literal"><span class="pre">for</span></tt> and <tt class="docutils literal"><span class="pre">id</span></tt> attributes, respectively. Each checkbox has an
<tt class="docutils literal"><span class="pre">id_for_label</span></tt> attribute to output the element&#8217;s ID.</p>
</div>
</div>
</div>
<div class="section" id="s-file-upload-widgets">
<span id="s-id5"></span><span id="file-upload-widgets"></span><span id="id5"></span><h3>File upload widgets<a class="headerlink" href="#file-upload-widgets" title="Permalink to this headline">¶</a></h3>
<div class="section" id="s-fileinput">
<span id="fileinput"></span><h4><tt class="docutils literal"><span class="pre">FileInput</span></tt><a class="headerlink" href="#fileinput" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.FileInput">
<em class="property">class </em><tt class="descname">FileInput</tt><a class="headerlink" href="#django.forms.FileInput" title="Permalink to this definition">¶</a></dt>
<dd><p>File upload input: <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type='file'</span> <span class="pre">...&gt;</span></tt></p>
</dd></dl>

</div>
<div class="section" id="s-clearablefileinput">
<span id="clearablefileinput"></span><h4><tt class="docutils literal"><span class="pre">ClearableFileInput</span></tt><a class="headerlink" href="#clearablefileinput" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.ClearableFileInput">
<em class="property">class </em><tt class="descname">ClearableFileInput</tt><a class="headerlink" href="#django.forms.ClearableFileInput" title="Permalink to this definition">¶</a></dt>
<dd><p>File upload input: <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type='file'</span> <span class="pre">...&gt;</span></tt>, with an additional checkbox
input to clear the field&#8217;s value, if the field is not required and has
initial data.</p>
</dd></dl>

</div>
</div>
<div class="section" id="s-composite-widgets">
<span id="s-id6"></span><span id="composite-widgets"></span><span id="id6"></span><h3>Composite widgets<a class="headerlink" href="#composite-widgets" title="Permalink to this headline">¶</a></h3>
<div class="section" id="s-multiplehiddeninput">
<span id="multiplehiddeninput"></span><h4><tt class="docutils literal"><span class="pre">MultipleHiddenInput</span></tt><a class="headerlink" href="#multiplehiddeninput" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.MultipleHiddenInput">
<em class="property">class </em><tt class="descname">MultipleHiddenInput</tt><a class="headerlink" href="#django.forms.MultipleHiddenInput" title="Permalink to this definition">¶</a></dt>
<dd><p>Multiple <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type='hidden'</span> <span class="pre">...&gt;</span></tt> widgets.</p>
<p>A widget that handles multiple hidden widgets for fields that have a list
of values.</p>
<dl class="attribute">
<dt id="django.forms.MultipleHiddenInput.choices">
<tt class="descname">choices</tt><a class="headerlink" href="#django.forms.MultipleHiddenInput.choices" title="Permalink to this definition">¶</a></dt>
<dd><p>This attribute is optional when the form field does not have a
<tt class="docutils literal"><span class="pre">choices</span></tt> attribute. If it does, it will override anything you set
here when the attribute is updated on the <a class="reference internal" href="fields.html#django.forms.Field" title="django.forms.Field"><tt class="xref py py-class docutils literal"><span class="pre">Field</span></tt></a>.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-splitdatetimewidget">
<span id="splitdatetimewidget"></span><h4><tt class="docutils literal"><span class="pre">SplitDateTimeWidget</span></tt><a class="headerlink" href="#splitdatetimewidget" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.SplitDateTimeWidget">
<em class="property">class </em><tt class="descname">SplitDateTimeWidget</tt><a class="headerlink" href="#django.forms.SplitDateTimeWidget" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper (using <a class="reference internal" href="#django.forms.MultiWidget" title="django.forms.MultiWidget"><tt class="xref py py-class docutils literal"><span class="pre">MultiWidget</span></tt></a>) around two widgets: <a class="reference internal" href="#django.forms.DateInput" title="django.forms.DateInput"><tt class="xref py py-class docutils literal"><span class="pre">DateInput</span></tt></a>
for the date, and <a class="reference internal" href="#django.forms.TimeInput" title="django.forms.TimeInput"><tt class="xref py py-class docutils literal"><span class="pre">TimeInput</span></tt></a> for the time.</p>
<p><tt class="docutils literal"><span class="pre">SplitDateTimeWidget</span></tt> has two optional attributes:</p>
<dl class="attribute">
<dt id="django.forms.SplitDateTimeWidget.date_format">
<tt class="descname">date_format</tt><a class="headerlink" href="#django.forms.SplitDateTimeWidget.date_format" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#django.forms.DateInput.format" title="django.forms.DateInput.format"><tt class="xref py py-attr docutils literal"><span class="pre">DateInput.format</span></tt></a></p>
</dd></dl>

<dl class="attribute">
<dt id="django.forms.SplitDateTimeWidget.time_format">
<tt class="descname">time_format</tt><a class="headerlink" href="#django.forms.SplitDateTimeWidget.time_format" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#django.forms.TimeInput.format" title="django.forms.TimeInput.format"><tt class="xref py py-attr docutils literal"><span class="pre">TimeInput.format</span></tt></a></p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-splithiddendatetimewidget">
<span id="splithiddendatetimewidget"></span><h4><tt class="docutils literal"><span class="pre">SplitHiddenDateTimeWidget</span></tt><a class="headerlink" href="#splithiddendatetimewidget" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.SplitHiddenDateTimeWidget">
<em class="property">class </em><tt class="descname">SplitHiddenDateTimeWidget</tt><a class="headerlink" href="#django.forms.SplitHiddenDateTimeWidget" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#django.forms.SplitDateTimeWidget" title="django.forms.SplitDateTimeWidget"><tt class="xref py py-class docutils literal"><span class="pre">SplitDateTimeWidget</span></tt></a>, but uses <a class="reference internal" href="#django.forms.HiddenInput" title="django.forms.HiddenInput"><tt class="xref py py-class docutils literal"><span class="pre">HiddenInput</span></tt></a> for
both date and time.</p>
</dd></dl>

</div>
<div class="section" id="s-selectdatewidget">
<span id="selectdatewidget"></span><h4><tt class="docutils literal"><span class="pre">SelectDateWidget</span></tt><a class="headerlink" href="#selectdatewidget" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="django.forms.extras.widgets.SelectDateWidget">
<em class="property">class </em><tt class="descname">SelectDateWidget</tt><a class="reference internal" href="../../_modules/django/forms/extras/widgets.html#SelectDateWidget"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.extras.widgets.SelectDateWidget" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper around three <a class="reference internal" href="#django.forms.Select" title="django.forms.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> widgets: one each for
month, day, and year. Note that this widget lives in a separate file from
the standard widgets.</p>
<p>Takes one optional argument:</p>
<dl class="attribute">
<dt id="django.forms.extras.widgets.SelectDateWidget.years">
<tt class="descname">years</tt><a class="headerlink" href="#django.forms.extras.widgets.SelectDateWidget.years" title="Permalink to this definition">¶</a></dt>
<dd><p>An optional list/tuple of years to use in the &#8220;year&#8221; select box.
The default is a list containing the current year and the next 9 years.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.forms.extras.widgets.SelectDateWidget.months">
<tt class="descname">months</tt><a class="headerlink" href="#django.forms.extras.widgets.SelectDateWidget.months" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>An optional dict of months to use in the &#8220;months&#8221; select box.</p>
<p>The keys of the dict correspond to the month number (1-indexed) and
the values are the displayed months.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">MONTHS</span> <span class="o">=</span> <span class="p">{</span>
    <span class="mi">1</span><span class="p">:</span><span class="n">_</span><span class="p">(</span><span class="s">&#39;jan&#39;</span><span class="p">),</span> <span class="mi">2</span><span class="p">:</span><span class="n">_</span><span class="p">(</span><span class="s">&#39;feb&#39;</span><span class="p">),</span> <span class="mi">3</span><span class="p">:</span><span class="n">_</span><span class="p">(</span><span class="s">&#39;mar&#39;</span><span class="p">),</span> <span class="mi">4</span><span class="p">:</span><span class="n">_</span><span class="p">(</span><span class="s">&#39;apr&#39;</span><span class="p">),</span>
    <span class="mi">5</span><span class="p">:</span><span class="n">_</span><span class="p">(</span><span class="s">&#39;may&#39;</span><span class="p">),</span> <span class="mi">6</span><span class="p">:</span><span class="n">_</span><span class="p">(</span><span class="s">&#39;jun&#39;</span><span class="p">),</span> <span class="mi">7</span><span class="p">:</span><span class="n">_</span><span class="p">(</span><span class="s">&#39;jul&#39;</span><span class="p">),</span> <span class="mi">8</span><span class="p">:</span><span class="n">_</span><span class="p">(</span><span class="s">&#39;aug&#39;</span><span class="p">),</span>
    <span class="mi">9</span><span class="p">:</span><span class="n">_</span><span class="p">(</span><span class="s">&#39;sep&#39;</span><span class="p">),</span> <span class="mi">10</span><span class="p">:</span><span class="n">_</span><span class="p">(</span><span class="s">&#39;oct&#39;</span><span class="p">),</span> <span class="mi">11</span><span class="p">:</span><span class="n">_</span><span class="p">(</span><span class="s">&#39;nov&#39;</span><span class="p">),</span> <span class="mi">12</span><span class="p">:</span><span class="n">_</span><span class="p">(</span><span class="s">&#39;dec&#39;</span><span class="p">)</span>
<span class="p">}</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Widgets</a><ul>
<li><a class="reference internal" href="#specifying-widgets">Specifying widgets</a></li>
<li><a class="reference internal" href="#setting-arguments-for-widgets">Setting arguments for widgets</a></li>
<li><a class="reference internal" href="#widgets-inheriting-from-the-select-widget">Widgets inheriting from the Select widget</a></li>
<li><a class="reference internal" href="#customizing-widget-instances">Customizing widget instances</a><ul>
<li><a class="reference internal" href="#styling-widget-instances">Styling widget instances</a></li>
<li><a class="reference internal" href="#styling-widget-classes">Styling widget classes</a></li>
</ul>
</li>
<li><a class="reference internal" href="#base-widget-classes">Base Widget classes</a></li>
<li><a class="reference internal" href="#built-in-widgets">Built-in widgets</a><ul>
<li><a class="reference internal" href="#widgets-handling-input-of-text">Widgets handling input of text</a><ul>
<li><a class="reference internal" href="#textinput"><tt class="docutils literal"><span class="pre">TextInput</span></tt></a></li>
<li><a class="reference internal" href="#numberinput"><tt class="docutils literal"><span class="pre">NumberInput</span></tt></a></li>
<li><a class="reference internal" href="#emailinput"><tt class="docutils literal"><span class="pre">EmailInput</span></tt></a></li>
<li><a class="reference internal" href="#urlinput"><tt class="docutils literal"><span class="pre">URLInput</span></tt></a></li>
<li><a class="reference internal" href="#passwordinput"><tt class="docutils literal"><span class="pre">PasswordInput</span></tt></a></li>
<li><a class="reference internal" href="#hiddeninput"><tt class="docutils literal"><span class="pre">HiddenInput</span></tt></a></li>
<li><a class="reference internal" href="#dateinput"><tt class="docutils literal"><span class="pre">DateInput</span></tt></a></li>
<li><a class="reference internal" href="#datetimeinput"><tt class="docutils literal"><span class="pre">DateTimeInput</span></tt></a></li>
<li><a class="reference internal" href="#timeinput"><tt class="docutils literal"><span class="pre">TimeInput</span></tt></a></li>
<li><a class="reference internal" href="#textarea"><tt class="docutils literal"><span class="pre">Textarea</span></tt></a></li>
</ul>
</li>
<li><a class="reference internal" href="#selector-and-checkbox-widgets">Selector and checkbox widgets</a><ul>
<li><a class="reference internal" href="#checkboxinput"><tt class="docutils literal"><span class="pre">CheckboxInput</span></tt></a></li>
<li><a class="reference internal" href="#select"><tt class="docutils literal"><span class="pre">Select</span></tt></a></li>
<li><a class="reference internal" href="#nullbooleanselect"><tt class="docutils literal"><span class="pre">NullBooleanSelect</span></tt></a></li>
<li><a class="reference internal" href="#selectmultiple"><tt class="docutils literal"><span class="pre">SelectMultiple</span></tt></a></li>
<li><a class="reference internal" href="#radioselect"><tt class="docutils literal"><span class="pre">RadioSelect</span></tt></a></li>
<li><a class="reference internal" href="#checkboxselectmultiple"><tt class="docutils literal"><span class="pre">CheckboxSelectMultiple</span></tt></a></li>
</ul>
</li>
<li><a class="reference internal" href="#file-upload-widgets">File upload widgets</a><ul>
<li><a class="reference internal" href="#fileinput"><tt class="docutils literal"><span class="pre">FileInput</span></tt></a></li>
<li><a class="reference internal" href="#clearablefileinput"><tt class="docutils literal"><span class="pre">ClearableFileInput</span></tt></a></li>
</ul>
</li>
<li><a class="reference internal" href="#composite-widgets">Composite widgets</a><ul>
<li><a class="reference internal" href="#multiplehiddeninput"><tt class="docutils literal"><span class="pre">MultipleHiddenInput</span></tt></a></li>
<li><a class="reference internal" href="#splitdatetimewidget"><tt class="docutils literal"><span class="pre">SplitDateTimeWidget</span></tt></a></li>
<li><a class="reference internal" href="#splithiddendatetimewidget"><tt class="docutils literal"><span class="pre">SplitHiddenDateTimeWidget</span></tt></a></li>
<li><a class="reference internal" href="#selectdatewidget"><tt class="docutils literal"><span class="pre">SelectDateWidget</span></tt></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="formsets.html">Formset Functions</a></li>
    
    
      <li>Next: <a href="validation.html">Form and field validation</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../index.html">Django 1.7.8.dev20150401230226 documentation</a>
        
          <ul><li><a href="../index.html">API Reference</a>
        
          <ul><li><a href="index.html">Forms</a>
        
        <ul><li>Widgets</li></ul>
        </li></ul></li></ul>
      </li>
  </ul>

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/ref/forms/widgets.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Apr 02, 2015</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="formsets.html" title="Formset Functions">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="validation.html" title="Form and field validation">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>